﻿using System;
using System.Data;
using System.Data.SqlClient;

namespace ado2
{
    public class DataHelper
    {
        private readonly string sql = "select * from students";
        private readonly string connStr = "server=.;database=grade;uid=sa;pwd=yoshiki";
        public static void PrintGradeInfo()
        {
            string connStr = "server=.;database=grade;uid=sa;pwd=yoshiki";

            SqlConnection conn = new SqlConnection(connStr);

            conn.Open();

            var sql = "select * from students";

            SqlCommand sqlCommand = new SqlCommand(sql, conn);
            var sdr = sqlCommand.ExecuteReader();

            Console.WriteLine("{0}\t{1}\t{2}", "id", "name", "score");
            while (sdr.Read())
            {
                Console.WriteLine("{0}\t{1}\t{2}", sdr["id"], sdr["name"], sdr["score"]);
            }
            conn.Close();
        }


        public void PrintGrade()
        { 



                SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, connStr);

                DataTable dataTable = new DataTable();

                dataAdapter.Fill(dataTable);

                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();

                Console.WriteLine("{0}\t{1}\t{2}", "id", "姓名", "分数");

                for (int i = 0; i < dataTable.Rows.Count; i++)
                {
                    Console.WriteLine("{0}\t{1}\t{2}", dataTable.Rows[i]["id"], dataTable.Rows[i]["name"], dataTable.Rows[i]["score"],);
                }

            }

    }
}
